<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="昵称">
                <a-input placeholder="请输入昵称" v-model="queryParam.nickname"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="手机号">
                <a-input placeholder="请输入手机号" v-model="queryParam.mobile"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-button type="primary" @click="tablePageChange(1)">查询</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :bordered="false">
      <a-table
        :rowKey="
          (r, i) => {
            return i
          }
        "
        :pagination="{
          current: queryParam.pageNo,
          total: this.totalCount,
          showSizeChanger: false,
          onChange: this.tablePageChange,
        }"
        :columns="columns"
        :data-source="list"
        :scroll="{ x: 'max-content' }"
      >
        <div slot="name" slot-scope="text, record">
          <div class="name">
            <div class="pic">
              <img :src="record.user_avatar" alt="" />
            </div>
            <div class="info">
              <span>{{ record.user_name }}</span>
            </div>
          </div>
        </div>
        <span slot="mobile" slot-scope="scope"> {{ scope.name }} / {{ scope.user_mobile }} </span>
        <span slot="old" slot-scope="scope"> {{ scope.old_parent_name || '-' }} </span>
        <span slot="count" slot-scope="scope">
          <template v-if="scope.count > 0">
            <span style="color: #1890ff; cursor: pointer" @click="showCount(scope)">{{ scope.count }}</span>
          </template>
          <template v-else>
            {{ scope.count }}
          </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { oldShareList } from '@/api/shareholder'
import { STable } from '@/components'
const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
  },
  {
    title: '会员信息',
    scopedSlots: {
      customRender: 'name',
    },
    width: 200,
  },
  {
    title: '姓名/电话',
    scopedSlots: {
      customRender: 'mobile',
    },
  },
  {
    title: '等级',
    dataIndex: 'level_name',
  },
  {
    title: '原推荐人',
    scopedSlots: {
      customRender: 'old',
    },
  },
  {
    title: '一级下级人数',
    scopedSlots: {
      customRender: 'count',
    },
  },
]
export default {
  components: {
    STable,
  },
  data() {
    return {
      // 搜索参数
      queryParam: {
        nickname: null,
        mobile: null,
        id: null,
        pageNo: 1,
        pageSize: 10,
      },
      // 请求的数据列表
      list: [],
      // 表格列配置
      columns,
      // 数据条数
      totalCount: 0,
    }
  },
  methods: {
    // 获取数据列表
    async getList() {
      const hide = this.$message.loading('加载中', 0)
      const res = await oldShareList(this.queryParam)
      if (res.code == 0) {
        this.totalCount = res.data.totalCount
        this.list = res.data.data
      }
      hide()
    },
    // 分页请求
    tablePageChange(e) {
      this.queryParam.pageNo = e
      this.getList()
    },
    // 显示下级列表弹窗
    showCount(e) {
      this.queryParam = {
        nickname: null,
        mobile: null,
        id: null,
        pageNo: 1,
        pageSize: 10,
      }
      this.$router.push('/plugins/shareholder/oldlist?id=' + e.user_id)
    },
  },
  mounted() {
    this.queryParam.id = this.$route.query.id
    this.getList()
  },
  watch: {
    '$route.query.id'(val) {
      this.queryParam.id = val
      this.getList()
    },
  },
}
</script>

<style lang="less" scoped>
.search {
  /deep/ .ant-card-body {
    padding-top: 0 !important;
    padding-bottom: 14px !important;
  }
}
.searchBox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-top: 14px;
    margin-right: 20px;
  }
  .select {
    display: flex;
    align-items: center;
    margin-top: 14px;
    margin-right: 20px;
  }
  .ant-btn {
    margin-top: 14px;
  }
}
.name {
  display: flex;
  align-items: center;
  .pic {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 24px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .info {
    flex: auto;
    width: 0;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    span {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    span:nth-child(2) {
      color: rgba(0, 0, 0, 0.45);
      margin-top: 6px;
    }
  }
}
.action {
  display: flex;
  align-items: center;
  .line {
    width: 1px;
    height: 14px;
    background-color: #d8d8d8;
  }
}
.level_one_count {
  text-decoration: underline;
  cursor: pointer;
  color: #ff4400;
}
</style>
